<?php
    session_start();
    include("includes/connect_db.php");
    include("includes/function.php");
    $id_kontak = $_POST['id_kontak'];
    $tipe = $_POST['tipe'];

    if ($tipe == 'Kontak') {
        $sql = "SELECT * FROM tb_kontak WHERE id_kontak = '$id_kontak'";
        $query = mysql_query($sql);
        $tampil = mysql_fetch_array($query);
        $nama = $tampil['nama_kontak'];
        $jenis_kelamin = $tampil['jenis_kelamin'];
        $alamat = $tampil['alamat'];
        $tanggal = $tampil['tanggal_lahir'];
        $email = $tampil['email'];

    } elseif ($tipe == 'Mahasiswa') {
        $sql = "SELECT * FROM f_tb_mhs WHERE nim = '$id_kontak'";
        $query = mysql_query($sql);
        $tampil = mysql_fetch_array($query);
        $nama = $tampil['nama'];
        $jenis_kelamin = $tampil['jenis_kelamin'];
        $alamat = $tampil['alamat_tinggal'];
        $tanggal = $tampil['tgl_lahir'];
        $nomor = $tampil['telepon'];
        $email = $tampil['email'];
    } else {
        $sql = "SELECT * FROM f_tb_master_pegawai WHERE nip_baru = '$id_kontak'";
        $query = mysql_query($sql);
        $tampil = mysql_fetch_array($query);
        $nama = $tampil['nama_lengkap'];
        $jenis_kelamin = $tampil['jenis_kelamin'];
        $alamat = $tampil['alamat'];
        $tanggal = $tampil['tgl_lahir'];
        $nomor = $tampil['telp'];
        $email = $tampil['email'];
    }
?>

<style>
    div{
        font-family: 'SEGOE UI';
    }
    
    #form-modalx {
    	margin: 0 0 0 -400px;
        width: 800px;
    }
    
    .profil-block {
        padding: 10px;
        background-color: #fff;
        -moz-box-shadow: 0px 1px 5px 1px #ddd;
        -webkit-box-shadow: 0px 1px 5px 1px #ddd;
        box-shadow: 0px 1px 5px 1px #ddd;
        border: 1px solid #ddd;
        margin-bottom: 20px;
    }

    #profil-detail{
        margin-left: 20px;
    }

    #profil-detail div{
        margin-bottom: 5px;
    }

    #profil-detail span{
        margin-left: 30px;
        font-family: "SEGOE UI";
        color: #0088cc;
    }
</style>


<div id="form-modalx" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-body">
        <div>                      
            <ul class="breadcrumb-modal" style="background-color: #0088cc; color: #FFF; text-shadow: none; font-family: 'SEGOE UI'">
                <input type="hidden" id="kontakTipe" value="<?php echo $tipe; ?>">
                <?php 
                    if ($tipe == 'Kontak') {
                ?>
                <li id="delete-kontak" style="cursor: pointer;" title="Hapus Kontak" data-placement="bottom" data-animation="true">
                    <i class="icon-trash icon-white"></i>
                    Hapus
                </li>
                <li id="edit-kontak" style="cursor: pointer;" title="Edit Kontak" data-placement="bottom" data-animation="true">
                    <i class="icon-edit icon-white"></i> 
                    Edit
                </li>
                <?php
                    } else {
                ?>
                <li id="delete-kontak" style="cursor: pointer; opacity: 0.7;" title="Hapus Kontak (Disabled)" data-placement="bottom" data-animation="true">
                    <i class="icon-trash icon-white"></i> 
                    Hapus
                </li>
                <li id="edit-kontak" style="cursor: pointer; opacity: 0.7;" title="Edit Kontak (Disabled)" data-placement="bottom" data-animation="true">
                    <i class="icon-edit icon-white"></i> 
                    Edit
                </li>
                <?php
                    }
                ?>
                <li id="add-kontak" style="cursor: pointer;" title="Tambah Kontak" data-placement="bottom" data-animation="true">
                    <i class="icon-plus icon-white"></i>
                    Tambah
                </li>
                <li class="pull-right" title="Keluar" data-placement="bottom" data-animation="true">
                    <i style="color: #FFF;" class="icon-remove close" data-dismiss="modal" aria-hidden="true"></i>
                </li>
            </ul>
        </div>
        <div id="profil-detail" style="background-color: #F5F5F5; color: #7B7B7B; font-family:'SEGOE UI'; overflow: hidden; padding: 10px;">
            <div style="float: left; width: 40%; padding: 10px; text-align: center" class="profil-block">
                <legend>
                    <div style="font-family: Segoe Print;">
                        <?php echo $nama;?>
                    </div>
                </legend>
                <img src="<?php echo cekGambar($id_kontak, 1, 2); ?>" style="width: 90%;" class="img-polaroid">
            </div>
            <div style="margin: 0 0 10px 10px; width: 50%; float: left" class="profil-block pull-right">
                <legend>
                    Basic Info
                </legend>
                <label>ID</label>
                <span><?php echo $id_kontak; ?></span>
                <label>Nama</label>
                <span><?php echo $nama; ?></span>
                <label>Jenis Kelamin</label>
                <span>
                    <?php 
                        if($jenis_kelamin == 'l'){
                            echo "Laki-Laki";
                        } elseif ($jenis_kelamin == 'p') {
                            echo "Perempuan";
                        }
                    ?>
                </span>
                <label>Alamat</label>
                <span><?php echo $alamat; ?></span>
                <label>Tanggal Lahir</label>
                <span><?php echo $tanggal; ?></span>
            </div>
            <div style="margin: 0 0 10px 10px; width: 50%; float: left" class="profil-block pull-right">
                <legend>
                    Kontak
                </legend>
                <label>Nomer</label>
                <?php
                    $sql = "SELECT * FROM tb_kontak_rincian WHERE id_kontak = '$id_kontak'";
                    $query = mysql_query($sql);
                    while ($hasil = mysql_fetch_array($query)) {
                        echo "<span>$hasil[no_hp]</span><br/>";
                    }
                ?>
                <label>Email</label>
                <span><?php echo $email; ?></span>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    function deleteKontak(){
        var formDelete = {
            id_kontak: <?php echo $_POST['id_kontak']; ?>
        };
        
        $.ajax({
            type: "POST",
            url: "act_kontak.php?aksi=1",
            data: formDelete, 
            cache: false, 
            success: function(kontak){
                if (kontak == 'sukses') {
                    alert('DATA BERHASIL DIHAPUS');
                    location.reload();
                };
            } 
        });            
    }

    function editKontak(){
        $.ajax({ 
            type: "POST",
            url: "kontak-edit-modal.php?id="+<?php echo $_POST['id_kontak']; ?>,
            cache: false, 
            success: function(msg){ 
                $("#tampil-modal-kontak").html(msg);
                $("#tampil-modal-kontak").fadeIn("medium");
            } 
        });
        return false;
    }

    function tambahKontak(){
        location.href = "kontak-tambah.php";
    }
    
    $(document).ready(function(){
        $('#form-modalx').modal('show');
        $('#delete-kontak').live('click',function(){
            if ($(this).parent('ul').find('#kontakTipe').val() == 'Kontak') {
                deleteKontak();
            };
        });
        $('#edit-kontak').click(function(){
            if ($(this).parent('ul').find('#kontakTipe').val() == 'Kontak') {
                $('#form-modalx').modal('hide');
                editKontak();
            };
        });
        $('#add-kontak').live('click',function(){
            tambahKontak();
        });

        $('#delete-kontak').tooltip();
        $('#edit-kontak').tooltip();
        $('#add-kontak').tooltip();

        tempView.parent('tr').css('font-weight','normal');
    });
</script>